#encoding=utf-8

import sys
import time
import email
import smtplib
import poplib

def send_mail():
    try:
        handle = smtplib.SMTP('smtp.163.com', 25)
        handle.login('itsky365@163.com', 'itsky365zhuxh')
        msg = 'To:27066778@qq.com\r\nFrom:itsky365@163.com\r\nSubject:this is from cnblogs\r\n'
        handle.sendmail('itsky365@163.com', '270667789@qq.com', msg)
        handle.close()
        return 1
    except smtplib.SMTPConnectError, e:
        print "error", e
        return 0

def check_mail():
    try:
        p = poplib.POP3('pop.163.com')
        p.user('itsky365@163.com')
        p.pass_('itsky365zhuxh')
        ret = p.stat()
        print ret
        msglist = p.list()
        print msglist[0]
        for msg in msglist[1]:
            print msg
    except poplib.error_proto, e:
        print 'login failed',e
        sys.exit(1)

if __name__ == "__main__":
    send_mail()
    #accept_mail()